import 'package:flutter/material.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:get/get.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/my_underline_tab_indicator.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/common/seckill_order_good_arr.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/seckill_controller/seckill_order_page_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/utils/color_util.dart';

class SeckillOrderPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();

  @override
  Widget build(BuildContext context) {
    Map<String, dynamic> argumentsMap = Get.arguments;
    int tabIndex = argumentsMap['tabIndex'];
    return GetBuilder<SeckillOrderPageController>(
      init: SeckillOrderPageController(),
      builder: (controller) {
        return Scaffold(
          backgroundColor: pageBgColor,
          appBar: AppBarUtil(
            title: '订单列表',
            backgroundColor: pageBgColor,
            actions: [
               commonPageController.userData.value.isAdmin == 1 ? InkWellUtil.shakeProofInkWell(Container(
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                child: Text(
                  '筛选',
                  style: TextStyle(
                    color: mainTextColor,
                    fontSize: 14.sp
                  ),
                ),
              ), () {
                controller.showScreenBody.value = true;
              },
              hoverColor: Colors.transparent,
              splashColor:  Colors.transparent,
              highlightColor:  Colors.transparent) : Container()
            ],
          ),
          body: Stack(
            children: [
              DefaultTabController(
                length: 5, 
                initialIndex: tabIndex,
                child: Column(
                  children: [
                    Container(
                      constraints: BoxConstraints(maxHeight: 44.h),
                      child: Material(
                        color: bgWhiteColor,
                        child: TabBar(  
                          indicator: MyUnderlineTabIndicator(
                            wantWidth: 20.w,
                            borderSide: BorderSide(
                              width: 5.h,
                              color: bgMainColor
                            )
                          ),
                          indicatorColor: bgMainColor,
                          labelColor: mainTextColor,
                          unselectedLabelColor: textSubtitleColor,
                          labelStyle: TextStyle(
                            fontSize: 14.sp
                          ),
                          unselectedLabelStyle: TextStyle(
                            fontSize: 14.sp
                          ),
                          onTap: (index) {
                            controller.tabIndex.value = index;
                            controller.getSeckillOrderList();
                          },
                          labelPadding: EdgeInsets.zero,
                          tabs: [
                            Tab(text: '全部'),
                            Tab(text: '待付款'),
                            Tab(text: '待收款'),
                            Tab(text: '已售出'),
                            Tab(text: '已取消')
                          ]
                        ),
                      ),
                    ),
                    // Expanded(child: TabBarView(
                    //   physics: NeverScrollableScrollPhysics(),
                    //   children: controller.dataArr.map((item) {
                    //     return SeckillOrderGoodArr(seckillOrderListVo: item, seckillOrderPageController: controller);
                    //   }).toList()
                    // ))
                    Expanded(child: Obx(() => SeckillOrderGoodArr(seckillOrderListVo: controller.dataArr[controller.tabIndex.value], seckillOrderPageController: controller)))
                  ],
                )
              ),
              Positioned(
                child: Obx(() => controller.showScreenBody.value ? Container(
                  color: Colors.black38,
                  child: Column(
                    children: [
                      Container(
                        color: bgWhiteColor,
                        width: 375.w,
                        height: 248.h,
                        alignment: Alignment.topCenter,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              height: 50.h,
                              color: bgWhiteColor,
                              padding: EdgeInsets.symmetric(horizontal: 16.w),
                              alignment: Alignment.centerLeft,
                              child: Text(
                                '空间名称',
                                style: TextStyle(
                                  color: textBlackColor,
                                  fontSize: 16.sp,
                                  fontWeight: FontWeight.bold
                                ),
                              ),
                            ),
                            Expanded(child: Container(
                              padding: EdgeInsets.symmetric(horizontal: 24.w),
                              child: ScrollConfigurationCommon(
                                child: SingleChildScrollView(
                                  child: Wrap(
                                    runSpacing: 12.h,
                                    spacing: 16.w,
                                    children: controller.dataArr[controller.tabIndex.value].meta!.teams!.map((item) {
                                      return InkWellUtil.shakeProofInkWell(Container(
                                        padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
                                        decoration: BoxDecoration(
                                          color: controller.screenArr.contains(item.id) ? bgRecoveryStatus : pageBgColor,
                                          borderRadius: BorderRadius.circular(5.w)
                                        ),
                                        child: Text(
                                          '${item.name}',
                                          style: TextStyle(
                                            color: controller.screenArr.contains(item.id) ? mainTextColor : textSubtitleColor,
                                            fontSize: 12.sp
                                          ),
                                        ),
                                      ), () {
                                        controller.changeScreenArr(item.id!);
                                      });
                                    }).toList()
                                  ),
                                ),
                              ),
                            )),
                            Container(
                              padding: EdgeInsets.symmetric(horizontal: 62.w, vertical: 16.h),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Container(
                                    width: 120.w,
                                    child: ButtonUtil(
                                      text: '重置', 
                                      fontSize: 14.sp, 
                                      borderRadius: 36.h, 
                                      height: 36.h, 
                                      bgColors: [
                                        bgWhiteColor,
                                        bgWhiteColor
                                      ],
                                      showBorder: true,
                                      borderColor: lineColor,
                                      textColor: textSubtitleColor,
                                      onTop: () {
                                        controller.screenArr.value = [];
                                        controller.showScreenBody.value = false;
                                        controller.getSeckillOrderList();
                                      }
                                    ),
                                  ),
                                  Container(
                                    width: 120.w,
                                    child: ButtonUtil(
                                      text: '确认', 
                                      fontSize: 14.sp, 
                                      borderRadius: 36.h, 
                                      height: 36.h, 
                                      onTop: () {
                                        controller.showScreenBody.value = false;
                                        controller.getSeckillOrderList();
                                      }
                                    ),
                                  )
                                ],
                              ),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ) : Container())
              )
            ],
          ),
        );
      },
    );
  }
}